USE [genshi]
GO

/****** Object:  Trigger [dbo].[Relics_limit]    Script Date: 2022/5/3 20:29:05 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TRIGGER [dbo].[Relics_limit] ON [dbo].[Relics]
Instead of insert
AS
BEGIN
	SET NOCOUNT ON;
	Declare @insertnum int;
	SELECT @insertnum = count(*) from inserted
	Declare @oldnum int;
	SELECT @oldnum = count(*) from Relics
	if (@insertnum + @oldnum) <= 1000
		begin
			insert into Relics
			select  * from inserted
		end
	else
		begin
			print('圣遗物总数不能超过1000')
			rollback transaction
		end
END
GO

ALTER TABLE [dbo].[Relics] ENABLE TRIGGER [Relics_limit]
GO

